home *** CD-ROM | disk | FTP | other *** search
/ PC go! 2008 April / PCgo 2008-04 (DVD).iso / interface / contents / demoversionen_3846 / 13664 / files / Data1.cab / sampletool.cs < prev    next >
Encoding:
Text File  |  2004-07-15  |  5.3 KB  |  194 lines

  1. //******************************************************************'
  2. //*                                                                *'
  3. //*                      TurboCAD for Windows                      *'
  4. //*                   Copyright (c) 1993 - 2004                    *'
  5. //*             International Microcomputer Software, Inc.         *'
  6. //*                            (IMSI)                              *'
  7. //*                      All rights reserved.                      *'
  8. //*                                                                *'
  9. //******************************************************************'
  10. using System;
  11. using System.Windows.Forms;
  12.  
  13. namespace TCCSharpTool
  14. {
  15.  
  16.     /// <summary>
  17.     /// Summary description for Class1.
  18.     /// </summary>
  19.  
  20.     public class SampleTool
  21.     {
  22.         const short NUM_TOOLS = 1;
  23.         //Toggle this to test loading buttons from .Bmp/.Res
  24.         const bool boolLoadFromBmp = false;
  25.       public SampleTool()
  26.         {
  27.             //
  28.             // TODO: Add constructor logic here
  29.             //
  30.         }
  31.  
  32.         public string Description
  33.         {
  34.             get
  35.             {
  36.                 return "TurboCAD CSharp Tool";
  37.             }
  38.         }
  39.  
  40.         public bool Run(object Tool)
  41.         {
  42.         
  43.             MessageBox.Show ("Add your code here");
  44.             return false;
  45.             
  46.         }
  47.  
  48.         public int GetToolInfo(out object CommandNames, out object MenuCaptions, out object StatusPrompts, out object ToolTips, out object Enabled, out object WantsUpdates)
  49.         {
  50.             try
  51.             {
  52.                 string[] SCommandNames = new string[NUM_TOOLS];
  53.                 string[,] SMenuCaptions = new string[NUM_TOOLS,2];
  54.                 string[] SStatusPrompts = new string[NUM_TOOLS];
  55.                 string[] SToolTips = new string[NUM_TOOLS];
  56.                 bool[] BEnabled = new bool[NUM_TOOLS];
  57.                 bool[] BWantsUpdates = new bool[NUM_TOOLS];
  58.                 int[] iIndex = {0,0};
  59.                 SCommandNames[0] = "Bonus|SDK Programming|C# Tool";
  60.                 SMenuCaptions.SetValue ("C# Tool",iIndex);
  61.                 iIndex[1] = 1;
  62.                 Array arTest = Array.CreateInstance (typeof(string),1,2);
  63.  
  64.                 arTest.SetValue ("test 1", 0, 0);
  65.                 arTest.SetValue ("test 2", 0, 1);
  66.  
  67.                 SMenuCaptions.SetValue ("Bonus",0,1);
  68.                 //SMenuCaptions[0, 1] = "Bonus";
  69.                 SStatusPrompts[0] = "C# Tool prompt";
  70.                 SToolTips[0] = "C# Tool tooltip";
  71.  
  72.                 BEnabled[0] = true;
  73.                 BWantsUpdates[0] = false;
  74.             
  75.                 CommandNames = SCommandNames;
  76.                 MenuCaptions = SMenuCaptions;
  77.                 StatusPrompts  = SStatusPrompts;
  78.                 ToolTips = SToolTips;
  79.                 Enabled = BEnabled;
  80.                 WantsUpdates = BWantsUpdates;
  81.  
  82.                 return NUM_TOOLS;
  83.             }
  84.             catch(Exception e)
  85.             {
  86.                 Console.WriteLine("An error occurred: '{0}'", e);
  87.                 throw;
  88.             }
  89.         }
  90.  
  91.         /// <summary>
  92.         /// Public Function GetPicture(ByVal LargeImage As Boolean, ByVal MonoImage As Boolean) As Object
  93.         /// </summary>
  94.         public object GetPicture(bool LargeImage, bool MonoImage)
  95.         {
  96.             System.Drawing.Bitmap TheImage;
  97.             TheImage = null;
  98.             if (GetButtonPicture(LargeImage, MonoImage, ref TheImage ) == true)
  99.             {
  100.                 ImageConverter imgConverter = new ImageConverter() ;
  101.                 return imgConverter.ImageToIpicture(TheImage);
  102.             }
  103.             return null;
  104.         }
  105.  
  106.         public bool CopyBitmap(bool LargeImage, bool MonoImage)
  107.         {
  108.             return true;
  109.         }
  110.  
  111.         public bool Initialize(object Tool)
  112.         {
  113.             return true;
  114.         }
  115.  
  116.         public bool UpdateToolStatus(object Tool, bool Enabled, bool Checked)
  117.         {
  118.             return true;
  119.         }
  120.         private bool GetButtonPicture(bool LargeImage, bool MonoImage, ref System.Drawing.Bitmap  theImage )
  121.         {
  122.             string s, s1;
  123.             bool bRet = false;
  124.         //define correct path to the icons here' 
  125. //        ' copy of these bmp files are located in TCVBNETTool directory
  126. //      'There are two ways to load images:  from .Bmp file(s) or from .RES resource.
  127. //        'In this demo, we control the loading by a private variable.
  128. //        Dim img As System.Drawing.Image
  129. //        Dim thisApp As System.Reflection.Assembly
  130. //        Dim file As System.IO.Stream
  131.         System.Reflection.Assembly thisApp;
  132.         System.IO.Stream file;
  133.         System.Drawing.Image img;
  134.         if (boolLoadFromBmp == true)
  135.         {
  136.             if (LargeImage)
  137.             {
  138.                 img = System.Drawing.Image.FromFile(s1); //'"LargeIcon.bmp")
  139.                 bRet = true;
  140.             }
  141.             else
  142.             {
  143.                 img = System.Drawing.Image.FromFile(s); //'"SmallIcon.bmp")
  144.                 bRet = true;
  145.             }
  146.         }
  147.         else
  148.         {
  149.                                                  
  150.             if (LargeImage)
  151.                 {
  152.                     thisApp = System.Reflection.Assembly.GetExecutingAssembly();
  153.                     file = thisApp.GetManifestResourceStream("TCCSharpTool.LargeIcon.bmp");
  154.                     img = System.Drawing.Image.FromStream(file);
  155.                     bRet = true;
  156.                 }
  157.             else
  158.                 {
  159.                     thisApp = System.Reflection.Assembly.GetExecutingAssembly();
  160.                     file = thisApp.GetManifestResourceStream("TCCSharpTool.SmallIcon.bmp");
  161.                     img = System.Drawing.Image.FromStream(file);
  162.                     bRet = true;
  163.             }
  164.  
  165.         }
  166.             theImage = (System.Drawing.Bitmap)img;
  167.             return bRet;
  168.  
  169.         }
  170.  
  171.  
  172.  
  173.     }
  174.  
  175.     public class ImageConverter : System.Windows.Forms.AxHost 
  176.     { 
  177.         public ImageConverter():base("59EE46BA-677D-4d20-BF10-8D8067CB8B33") 
  178.         { 
  179.         } 
  180.  
  181.         public  stdole.IPictureDisp ImageToIpicture(System.Drawing.Image image) 
  182.         { 
  183.             return (stdole.IPictureDisp)ImageConverter.GetIPictureDispFromPicture(image); 
  184.         } 
  185.  
  186.         public System.Drawing.Image IPictureToImage(stdole.StdPicture picture) 
  187.         { 
  188.             return ImageConverter.GetPictureFromIPicture(picture); 
  189.         } 
  190.     } 
  191.  
  192.  
  193. }
  194.